// pages/movie/movie-detail/movie-detail.js
var app = getApp();
Page({
  data: {
    showAllDesc: false,
    movie: {}
  },
  onLoad (params) {
    // 页面初始化 options为页面跳转所带来的参数
    const that = this;
    const url = app.globalData.doubanBase + app.globalData.subject + params.id;
    console.log(params.id);
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 10000
    });
    wx.request({
      url: url,
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: { 'content-type': 'text' }, // 设置请求的 header
      success: function (res) {
        console.log(res.data.genres);
        const data = res.data;
        const readyData = {};
        // 人物信息
        const directorsAndCasts = [];
        for(let i in data.directors){
          directorsAndCasts.push(data.directors[i]);
        }
        for(let j in data.casts){
          directorsAndCasts.push(data.casts[j]);
        }
        // 类型
        // const genre = " ";
        const separate = "/";
        // for (let k in data.genres){
        //   genre += data.genres[k] + separate;
        // }
        // genre = genre.substring(0, genre.length - separate.length);
        // const countrise = "国家："
        // for(let g in data.countries){
        //   countrise += data.countries[g] + separate;
        // }
        // countrise = countrise.substring(0,countrise.length - separate.length);
        readyData["movie"] = {
          id: data.id,
          title: data.title,
          images: data.images,
          directorsAndCasts: directorsAndCasts,
          collectCount: data.collect_count,
          commentsCount: data.comments_count,
          wishCount: data.wish_count,
          reviewsCount: data.reviews_count,
          // countries: countries,
          doCount: data.do_count,
          // genres: genres,
          originalTitle: "原名：" + data.original_title,
          rating: data.rating,
          ratingsCount: data.ratings_count + "人",
          subtype: data.subtype,
          summary: data.summary,
          shareUrl: data.share_url,
          year: data.year
      }
      that.setData(readyData);
      }
    })
  },
  /** 用户点击想看 */
  handleWishtap: function (event) {
    wx.showModal({
      title: '提示',
      content: '一起去看吧',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
        }
      },
      showCancel: false
    });
  }
 
})